<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
<script>
/*var obj = {}; 
var val = "Hello";
Object.defineProperty(obj, "name", {
	set: function(value) {
		console.log("set");
		val = value;
	},
	get: function() {
		console.log("get");
		return val;
	}
})
var obj2 = {};
var val2 = "Hello2";
obj2.__defineSetter__("name", function(value) {
    console.log("setter");
    val2 = value;
});
obj2.__defineGetter__("name", function() {
    console.log("getter");
    return val2;
});*/
var model = {
	name: "wiz",
	age: 23,
	hasCar: false,
}
function ObserverFactory(model) {
	for(var property in model) {
		(function(prop) {
			model.__defineSetter__(prop, function(value) {
				console.log(prop + "的setter");
				this.value = value;
			});
			model.__defineGetter__(prop, function() {
				console.log(prop + "的getter");
				return this.value;
			});
		})(property);
	}
}
ObserverFactory(model);
model.name = "wiz";
console.log(model.name);
</script>
</body>
</html>
